#include "objectmanager.h"
#include "Engine2D/dxsprite.h"
#include "staticobject.h"

using namespace std;

ObjectManager::ObjectManager()
{ }

void ObjectManager::CreateObject(int objectId, float x, float y, int layer)
{
    if (mSprite.find(objectId) == mSprite.end())
    {
        char path[100] = "Data\\Mario Sprites\\";
        char* nameImg = "";
        switch (objectId)
        {
            case 1: nameImg = "cloud1.png"; break;
            case 2: nameImg = "cloud2.png"; break;
            case 3: nameImg = "grass.png"; break;
            case 4: nameImg = "hill.png"; break;
        }
        strcat(path, nameImg);
        mSprite[objectId] = new DXSprite(path, D3DCOLOR_XRGB(0, 0, 0), 1, 1);
    }
    vObject.push_back(new StaticObject(mSprite[objectId], x, y, layer));
    return;
}

void ObjectManager::DestroyObject(GameObject* object)
{
    vector<GameObject*>::iterator it = vObject.begin();
    while (it != vObject.end())
    {
        if ((*it) == object)
        {
            delete (*it);
            vObject.erase(it);
            break;
        }
        ++it;
    }
    return;
}

vector<GameObject*> ObjectManager::GetObjects()
{
    return vObject;
}

ObjectManager::~ObjectManager()
{ }